package cc.wsyw126.java.nowcoder.offerdidi.two;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/4/23.
 * 思路
 *
 * 按照x排序
 * 对y求最大递增序列
 */
public class Two {
    public static void main(String[] args) {
        Two one = new Two();
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            Integer integer = Integer.valueOf(s);
            ArrayList<node> nodes = new ArrayList<>();
            for (int i = 0; i < integer; i++) {
                String s1 = sc.nextLine();
                String[] split = s1.split(" ");
                node node = one.new node(Integer.valueOf(split[0]), Integer.valueOf(split[1]));
                nodes.add(node);
            }
            Collections.sort(nodes, new Comparator<node>() {
                @Override
                public int compare(node o1, node o2) {
                    return o1.x - o2.x;
                }
            });
            int max = 1;
            int my = doCount(nodes);
            max = my > max ? my : max;
            System.out.println(max);
        }
    }

    private static int doCount(ArrayList<node> nodes) {
        int[] counts = new int[nodes.size()];
        counts[0]=1;
        for (int i = 1; i < nodes.size(); i++) {
            int max= 0;
            for (int j = i-1; j >=0; j--) {
                if (max<counts[j] && nodes.get(i).y>nodes.get(j).y) {
                    max=counts[j];
                }
            }
            counts[i]=max+1;
        }
        int max= 0;
        for (int i = 0; i < nodes.size(); i++) {
            max=max<counts[i]?counts[i]:max;
        }
        return max;
    }

    private class node {
        private int x;
        private int y;

        public node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}
